<?php

class ControllerModuleCatpro extends Controller {

    protected function index($setting) {
        $this->language->load('module/catpro');



        $this->data['button_cart'] = $this->language->get('button_cart');

        $this->load->model('catalog/product');

        $this->load->model('tool/image');

        $this->data['products'] = array();
//		print_r($setting); die; 
        $data = array(
            'sort' => 'p.sort_order',
            'order' => 'DESC',
            'start' => 0,
            'limit' => $setting['limit'],
            'filter_category_id' => $setting['category_id']
        );

        $category = $this->model_catalog_category->getCategory($setting['category_id']);
        
        $this->data['catimage'] = $this->model_tool_image->resize($category['image'], $setting['image_width'], $setting['image_height']);
       
        $this->data['catbacs'] = $this->model_tool_image->resize($category['image'], 84, 17);
        
        $this->data['catid'] = $setting['category_id'];

        $this->data['heading_title'] = isset($category['name']) ? $category['name'] : '';

        $results = $this->model_catalog_product->getProducts($data);
       
        foreach ($results as $result) {


            if ($result['image']) {
                $image = $this->model_tool_image->resize($result['image'], $setting['image_width'], $setting['image_height']);
            } else {
                $image = false;
            }

            if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
                $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
            } else {
                $price = false;
            }

            if ((float) $result['special']) {
                $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')));
            } else {
                $special = false;
            }

            if ($this->config->get('config_review_status')) {
                $rating = $result['rating'];
            } else {
                $rating = false;
            }

            $this->data['products'][] = array(
                'product_id' => $result['product_id'],
                'thumb' => $image,
                'name' => $result['name'],
                
                'price' => $price,
                'special' => $special,
                'rating' => $rating,
                'reviews' => sprintf($this->language->get('text_reviews'), (int) $result['reviews']),
                'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']),
            );
        }
      
        if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/catpro.tpl')) {
            $this->template = $this->config->get('config_template') . '/template/module/catpro.tpl';
        } else {
            $this->template = 'default/template/module/catpro.tpl';
        }

        $this->render();
    }

}

?>